﻿<sdk:Page x:Class="Corina.Lantern.Hub.Views.Device.BuyDeviceView"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:controls="clr-namespace:Corina.Controls.Silverlight;assembly=Corina.Controls.Silverlight"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
          xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
          xmlns:localViewmodel="clr-namespace:Corina.Lantern.Hub.Viewmodels"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
          xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
          xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
          FontSize="14"
          Style="{StaticResource PageStyle}"
          d:DesignHeight="480"
          d:DesignWidth="900"
          mc:Ignorable="d">

    <sdk:Page.Resources>
        <ItemsPanelTemplate x:Key="temp_deviceitem_panel">
            <toolkit:WrapPanel>
                <i:Interaction.Behaviors>
                    <ei:FluidMoveBehavior AppliesTo="Children"
                                          Duration="0:0:0.5"
                                          InitialTag="DataContext"
                                          Tag="DataContext">
                        <ei:FluidMoveBehavior.EaseY>
                            <CubicEase EasingMode="EaseOut" />
                        </ei:FluidMoveBehavior.EaseY>
                        <ei:FluidMoveBehavior.EaseX>
                            <CubicEase EasingMode="EaseOut" />
                        </ei:FluidMoveBehavior.EaseX>
                    </ei:FluidMoveBehavior>
                </i:Interaction.Behaviors>
            </toolkit:WrapPanel>
        </ItemsPanelTemplate>

        <Style x:Key="style_deviceitem" TargetType="ListBoxItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Grid>

                            <!--
                                <i:Interaction.Triggers>
                                <i:EventTrigger EventName="MouseLeftButtonDown">
                                <ei:CallMethodAction MethodName="AddToCar" TargetObject="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType=navigation:Page}}" />
                                </i:EventTrigger>
                                </i:Interaction.Triggers>
                            -->

                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00"
                                                                           Duration="00:00:00.0010000"
                                                                           Storyboard.TargetName="border"
                                                                           Storyboard.TargetProperty="(UIElement.Visibility)">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed" />
                                    <VisualState x:Name="Disabled" />
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>

                            <Grid Background="White" Opacity="0" />
                            <Border x:Name="border"
                                    Margin="6"
                                    BorderBrush="{StaticResource COLOR_GRAY}"
                                    BorderThickness="1"
                                    CornerRadius="5"
                                    Visibility="Collapsed" />
                            <StackPanel Margin="12">
                                <Path Width="68"
                                      Height="68"
                                      Margin="0,0,0,0"
                                      Data="{Binding Converter={StaticResource StringToPathGeometryConverter},
                                                     Source={StaticResource ICON_MODEM}}"
                                      Fill="{StaticResource COLOR_LIGHTDARK}"
                                      RenderTransformOrigin="0.5,0.5"
                                      Stretch="Uniform">
                                    <Path.RenderTransform>
                                        <TransformGroup>
                                            <RotateTransform Angle="0" />
                                            <ScaleTransform ScaleX="1" ScaleY="1" />
                                        </TransformGroup>
                                    </Path.RenderTransform>
                                    <Path.Effect>
                                        <DropShadowEffect ShadowDepth="0" />
                                    </Path.Effect>
                                </Path>
                                <TextBlock Margin="0,3">
                                    <Run Text="{Binding DeviceSn}" />
                                    <Run Text="（" />
                                    <Run Foreground="{StaticResource COLOR_BLUE}" Text="￥" />
                                    <Run Foreground="{StaticResource COLOR_BLUE}" Text="{Binding RatePrice}" />
                                    <Run Text="）" />
                                </TextBlock>
                                <TextBlock Margin="0,3" Text="{Binding Kind}" />
                                <HyperlinkButton Content="购买">
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="Click">
                                            <ei:CallMethodAction MethodName="AddToCar" TargetObject="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType=navigation:Page}}" />
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </HyperlinkButton>
                            </StackPanel>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </sdk:Page.Resources>

    <sdk:Page.DataContext>
        <localViewmodel:BuyDeviceViewmodel />
    </sdk:Page.DataContext>

    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <toolkit:BusyIndicator IsBusy="{Binding IsBusy}">
                <ListBox Background="Transparent"
                         ItemContainerStyle="{StaticResource style_deviceitem}"
                         ItemsPanel="{StaticResource temp_deviceitem_panel}"
                         ItemsSource="{Binding ItemsCollection}"
                         ScrollViewer.HorizontalScrollBarVisibility="Disabled" />
            </toolkit:BusyIndicator>
        </Grid>

        <toolkit:Expander Grid.Column="1"
                          ExpandDirection="Right"
                          IsExpanded="True">
            <Grid Width="300">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Path Width="64"
                          Height="64"
                          Margin="0,0,0,0"
                          AllowDrop="True"
                          Data="{Binding Converter={StaticResource StringToPathGeometryConverter},
                                         Source={StaticResource ICON_SHOPCAR}}"
                          Fill="{StaticResource COLOR_DARK}"
                          RenderTransformOrigin="0.5,0.5"
                          Stretch="Uniform">
                        <Path.RenderTransform>
                            <TransformGroup>
                                <RotateTransform Angle="0" />
                                <ScaleTransform ScaleX="1" ScaleY="1" />
                            </TransformGroup>
                        </Path.RenderTransform>

                    </Path>
                    <Grid Width="24"
                          Height="24"
                          HorizontalAlignment="Left"
                          VerticalAlignment="Top">
                        <Ellipse Fill="{StaticResource COLOR_BLUE}" />
                        <TextBlock HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Text="{Binding ShopingCollection.Count}" />
                    </Grid>
                    <TextBlock Grid.Column="1"
                               Margin="12,0,0,0"
                               VerticalAlignment="Bottom">
                        <Run Text="合计：" />
                        <Run FontSize="32"
                             Foreground="Red"
                             Text="￥" />
                        <Run FontSize="32"
                             Foreground="Red"
                             Text="{Binding TotalAmount,
                                            Mode=OneWay}" />
                    </TextBlock>
                </Grid>

                <ListBox Grid.Row="1"
                         Margin="0,12"
                         ItemsSource="{Binding ShopingCollection}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <TextBlock>
                                    <Run Text="{Binding DeviceSn}" />
                                    <Run Text="  " />
                                    <Run Text="{Binding Kind}" />
                                </TextBlock>
                                <controls:PathButton Grid.Column="1"
                                                     Width="16"
                                                     Height="16"
                                                     Margin="12,0,0,0"
                                                     Command="{Binding DataContext.RemoveCarItemCommand,
                                                                       RelativeSource={RelativeSource FindAncestor,
                                                                                                      AncestorType=navigation:Page}}"
                                                     CommandParameter="{Binding}"
                                                     Foreground="{StaticResource COLOR_BLUE}"
                                                     PathData="{StaticResource ICON_DELETE}" />
                            </Grid>

                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Grid>
        </toolkit:Expander>
    </Grid>
</sdk:Page>
